<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class IndexController extends Controller{
	//构造函数
	public function __init()
	{
		
	}
	
    public function index(){
    	
		//首页侧边导航及二级三级导航
		$gcategories = $this->get_gcategories();
		//p($gcategories);exit;
		View::with('gcategories',$gcategories);
		
		//首页seo
		$indexseo = $this->get_indexseo();
		View::with('indexseo',$indexseo);
		
        View::make();
    }
	//退出
	public function logout(){
		session_unset();
		session_destroy();
		//跳转到登录页
		go(U('Index/index'));
	}
		
	
	//seo
	function get_indexseo(){
		$data = array(
			'title' => '国美在线-国美电器官方网上商城,中国领先专业的综合网购平台,正品低价、快速送达、安心服务!',
			'Keywords' => '国美,国美在线,国美电器,国美在线官方旗舰店,国美电器网上商城,,电视,洗衣机,电脑,手机,数码,空调,电脑配件,生活电器',
			'content' => '国美在线(gome.com.cn)国美电器唯一官方网上商城，中国领先的专业家电网购平台.全球品牌电视、洗衣机、电脑、手机、数码、空调、电脑配件、生活电器、网络产品等正品行货，更低价格，更快送达，为您提供便捷、诚信的服务.',
		);
		return $data;
	}
	
   //取得商品分类数据     
	function get_gcategories()
	{
        $gcateModel = new \Common\Model\Gcate;
		//所有数据
		$data = $gcateModel->get();
		$data = Data::channelLevel($data, $p_id = 0, $html = "&nbsp;", $fieldPri = 'cate_id', $fieldPid = 'p_id', $level = 1); 
        return $data;	    
	}
	
	
	
	
	
	function get_gcategories1()
	{
        $gcateModel = new \Common\Model\Gcate;
		//取1级分类的下级分类
		$data = $gcateModel->getMy(0);
		p($data);exit;
        foreach( $data as $key =>$val){
        	//取2级分类的下级分类
			$children = $gcateModel->getMy($val['cate_id']);
        	foreach( $children as $k=>$value){
        		//取3级分类的下级分类
				$third_children = $gcateModel->getMy($value['cate_id']);
				
        		$children[$k]['children'] = $third_children;	
        		unset($third_children);     
        	}
        	$data[$key]['children'] = $children;
        	unset($children);
			
        }
        return $data;	    
	}
	
  
	
	
}
